﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using _MetalSlug.Weapons.Units;
using Microsoft.Xna.Framework;

namespace _MetalSlug.Mementoes
{
    public class BulletMemento : IMemento
    {
        Bullet.TYPE_BULLET type;
        public Bullet.TYPE_BULLET Type
        {
            get { return type; }
        }

        Vector2 topLeft;
        public Vector2 TopLeft
        {
            get { return topLeft; }
        }

        Vector2 direction;
        public Vector2 Direction
        {
            get { return direction; }
        }

        public BulletMemento(Bullet RepresentBullet)
        {
            type = RepresentBullet.Type;
            topLeft = RepresentBullet.TopLeft;
            direction = RepresentBullet.Direction;
        }

        public BulletMemento(XmlElement Element)
        {
            type = (Bullet.TYPE_BULLET)Enum.Parse(typeof(Bullet.TYPE_BULLET), Element.GetAttribute("Type"));
            float X, Y;
            X = float.Parse(Element.GetAttribute("X"));
            Y = float.Parse(Element.GetAttribute("Y"));
            topLeft = new Vector2(X, Y);

            X = float.Parse(Element.GetAttribute("DirectX"));
            Y = float.Parse(Element.GetAttribute("DirectY"));
            direction = new Vector2(X, Y);
        }

        public XmlElement ToXML(XmlDocument Doc)
        {
            XmlElement Element = Doc.CreateElement("Bullet");
            Element.SetAttribute("Type",Type.ToString());
            Element.SetAttribute("X", TopLeft.X.ToString());
            Element.SetAttribute("Y", TopLeft.Y.ToString());
            Element.SetAttribute("DirectX", Direction.X.ToString());
            Element.SetAttribute("DirectY", Direction.Y.ToString());
            return Element;
        }
    }
}
